package FenxiaoService

import (
	"context"
	"gdshop-font-api-go/app/request/FenxiaoReq"
	"gdshop-font-api-go/app/service/MemberBaseService"
	"gdshop-font-api-go/library/response"
)

func Index(ctx context.Context, parames *FenxiaoReq.Index) *response.JsonResponse {
	memberId := int(parames.MemberId)
	// 读取当前会员信息和推荐人信息
	memberModel, err := MemberBaseService.GetMemberModel(ctx, memberId)
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	fanhui := GetMemberWithdrawInfo(ctx, memberId)
	// 订单相关的
	fanhuiOrder := GetMemberWithdrawOrderInfo(ctx, memberId)
	for k, v := range fanhuiOrder {
		fanhui[k] = v
	}
	// 团队人数
	fanhui["team_num"] = float64(GetTeamNum(ctx, memberId))

	// 读取当前会员信息和推荐人信息
	fanhui["nickname"] = memberModel.Nickname
	fanhui["avatar"] = memberModel.Avatar
	fanhui["referrer"] = "无" // 推荐人

	return response.SuccessByRequestMessageData(nil, "成功", fanhui)
}
